package com.sscw.task.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import com.sscw.task.entity.MRankArcadeMachinePO;
import com.sscw.task.mapper.MRankArcadeMachineMapper;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;

@Repository
public class MRankArcadeMachineDAO extends BaseDAO<MRankArcadeMachineMapper, MRankArcadeMachinePO> {

    public List<MRankArcadeMachinePO> findWeekRankList(LocalDate startOfWeek, LocalDate endOfWeek, Integer rankType, Integer size) {
        LambdaQueryWrapper<MRankArcadeMachinePO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MRankArcadeMachinePO::getStartDate, startOfWeek);
        queryWrapper.eq(MRankArcadeMachinePO::getEndDate, endOfWeek);
        queryWrapper.eq(MRankArcadeMachinePO::getRankType, rankType);
        queryWrapper.orderByDesc(MRankArcadeMachinePO::getHighestPoints);
        queryWrapper.last("limit 0," + size);
        return getBaseMapper().selectList(queryWrapper);
    }

    public MRankArcadeMachinePO findUserRank(LocalDate startOfWeek, LocalDate endOfWeek, Integer rankType, Long userId) {
        LambdaQueryWrapper<MRankArcadeMachinePO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(MRankArcadeMachinePO::getStartDate, startOfWeek);
        queryWrapper.eq(MRankArcadeMachinePO::getEndDate, endOfWeek);
        queryWrapper.eq(MRankArcadeMachinePO::getRankType, rankType);
        queryWrapper.eq(MRankArcadeMachinePO::getUserId, userId);
        return getBaseMapper().selectOne(queryWrapper);
    }
}
